using System;
using System.Collections.Generic;
using System.Linq;

namespace OrbitOne.Elmah.Logic
{
    /// <summary>
    /// Represents a Search Record.
    /// </summary>
    public class SearchRecord
    {
        #region Properties
        /// <summary>
        /// Gets the key of the search record.
        /// </summary>
        public string Key { get; private set; }

        /// <summary>
        /// Gets the count of the Errors in the record.
        /// </summary>
        public int Count { get; private set; }
        /// <summary>
        /// Gets the most recent time of the Errors.
        /// </summary>
        public TimeSpan MostRecent { get; private set; }
        /// <summary>
        /// Gets the Errors
        /// </summary>
        public IEnumerable<OrbitOneElmahErrorFacade> Errors { get; private set; } 
        #endregion

        #region Constructor
        /// <summary>
        /// Creates a new search record
        /// </summary>
        /// <param name="key">The key of the search record.</param>
        /// <param name="errors">The errors</param>
        public SearchRecord(string key, IEnumerable<OrbitOneElmahErrorFacade> errors, int count, DateTime? mostRecent)
        {
            this.Errors = errors;
            this.Key = key;
            if(mostRecent.HasValue)
            {
                this.MostRecent = DateTime.Now - mostRecent.Value;
            }
            this.Count = count;
        } 
        #endregion
    }
}